package com.lovo.csc.controller;


import com.lovo.csc.entity.Maintain;
import com.lovo.csc.entity.Purchase;
import com.lovo.csc.entity.Register;
import com.lovo.csc.service.IMaintainService;
import com.lovo.csc.service.IPurchaseService;
import com.lovo.csc.service.IRegisterService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    IRegisterService registerService;

    @Autowired
    IMaintainService maintainService;


    @GetMapping("findAll")
    public List<Register> findAll(){

        List<Register> findAll = registerService.list();
        return  findAll;
    }
    @DeleteMapping("del")
    public boolean del(int id){
    registerService.removeById(id);
    return true;
    }
    @PutMapping("save")
    public boolean save(){

       List<Register> registers = registerService.list();
       for (Register register : registers){
           Maintain maintain = new Maintain();
           maintain.setMGrade(register.getRGrade());
           maintain.setMCompany(register.getRCompany());
           maintain.setMShimg(register.getRShimg());
           maintain.setMZiimg(register.getRZiimg());
           maintain.setMRealname(register.getRRealname());
           maintain.setMGender(register.getRGender());
           maintain.setMPhone(register.getRPhone());
           maintain.setMPwd(register.getRPwd());
           maintain.setMName(register.getRName());
           maintainService.save(maintain);
       }
       return true;
    }



}
